package impl

import (
	"klotski/pojo"
	"klotski/socket/observer"
)

type Controller struct {
	processes []observer.Subscriber
}

func (c *Controller) AddProcess(process ...observer.Subscriber) {
	c.processes = append(c.processes, process...)

}

func (c *Controller) RemoveProcess(process observer.Subscriber) {
	for i, o := range c.processes {
		if o == process {
			c.processes = append(c.processes[:i], c.processes[i+1:]...)
			break
		}
	}
}

func (c *Controller) Notify(client *pojo.Client, request *pojo.RequestPkg) {
	for _, observer := range c.processes {
		observer.Update(client, request)
	}
}
